﻿/**********************************************
系统:Ebada物流企业ERP
模块:示例
作者:Rabbit
创建时间:2011-2-28
最后一次修改:2011-2-28
***********************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using DevExpress.XtraGrid.Columns;
using System.Reflection;
using Ebada.Client;
using DevExpress.XtraGrid.Views.Base;
using Ebada.Client.Platform;
using System.Collections;

namespace Ebada.Modules.Vehicle
{

    public partial class UCVehicleActivity : DevExpress.XtraEditors.XtraUserControl {
        private GridViewOperation<VehicleActivity> gridViewOperation;
        public event SendDataEventHandler<VehicleActivity> FocusedRowChanged;
        private VehicleActivity row;
        frmVehicleActivityBXEdit f = new frmVehicleActivityBXEdit();
        frmVehicleActivityNEdit f2 = new frmVehicleActivityNEdit();
        frmVehicleActivityXEdit f3 = new frmVehicleActivityXEdit();
        private string operType = "";
        private string warning = "";

        public string Warning
        {
            get { return warning; }
            set { warning = value; }
        }

        public string OperType
        {
            get { return operType; }
            set {
                operType = value;
                if (value == "1")
                {
                    gridViewOperation = new GridViewOperation<VehicleActivity>(gridControl1, gridView1, barManager1, f);
                }
                if (value == "2" || value == "3" || value == "4")
                {
                   
                    gridViewOperation = new GridViewOperation<VehicleActivity>(gridControl1, gridView1, barManager1, f2);
                    f2.OperType = value;
                }
                if (value == "5" || value == "6" || value == "7")
                {
                    
                    gridViewOperation = new GridViewOperation<VehicleActivity>(gridControl1, gridView1, barManager1, f3);
                    f3.OperType = value;
                }
                gridViewOperation.CreatingObjectEvent += gridViewOperation_CreatingObjectEvent;
                gridViewOperation.BeforeAdd += new ObjectOperationEventHandler<VehicleActivity>(gridViewOperation_BeforeAdd);
                gridViewOperation.AfterAdd += new ObjectEventHandler<VehicleActivity>(gridViewOperation_AfterAdd);
                gridViewOperation.BeforeEdit += new ObjectOperationEventHandler<VehicleActivity>(gridViewOperation_BeforeEdit);
                gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gridView1_FocusedRowChanged);
                initColumns();
                if (warning == "")
                {
                    LoadData();
                }
                else
                {
                    LoadData2();
                }
            }
        }

        public UCVehicleActivity() {

            InitializeComponent();
            initImageList();
            //LoadData();
        }

        void gridViewOperation_BeforeEdit(object render, ObjectOperationEventArgs<VehicleActivity> e)
        {
            
        }
    
        /// <summary>
        /// 设置隐藏列
        /// </summary>
        void initColumns() {

            if (operType=="1")
            {
                gridView1.Columns[0].Visible = false;
                gridView1.Columns[6].Visible = false;
                gridView1.Columns[7].Visible = false;
                gridView1.Columns[13].Visible = false;
                gridView1.Columns[15].Visible = false;
                gridView1.Columns[10].Caption = "保险日期起";
                gridView1.Columns[11].Caption = "保险日期止";
                gridView1.Columns[12].Caption = "办理日期";
                gridView1.Columns[14].Caption = "保险单位";
                gridView1.Columns[16].Caption = "经手人";
                gridView1.Columns[17].Caption = "车辆类型";
                gridView1.Columns[18].Caption = "承保险种";
            }
            if (operType == "2" || operType == "3" || operType == "4")
            {
                gridView1.Columns[0].Visible = false;
                gridView1.Columns[6].Visible = false;
                gridView1.Columns[7].Visible = false;
                gridView1.Columns[9].Visible = false;
                gridView1.Columns[13].Visible = false;
                gridView1.Columns[15].Visible = false;
                gridView1.Columns[17].Visible = false;
                gridView1.Columns[18].Visible = false;
                gridView1.Columns[8].Caption = "费用金额";
                gridView1.Columns[10].Caption = "此次审核日期";
                gridView1.Columns[11].Caption = "下次审核日期";
                gridView1.Columns[12].Caption = "预警日期";
                gridView1.Columns[14].Caption = "收费单位名称";
                gridView1.Columns[16].Caption = "操作人";
            }
            if (operType == "5" || operType == "6" || operType == "7")
            {
                gridView1.Columns[0].Visible = false;
                gridView1.Columns[11].Visible = false;
                gridView1.Columns[12].Visible = false;
                gridView1.Columns[13].Visible = false;
                gridView1.Columns[15].Visible = false;
                gridView1.Columns[17].Visible = false;
                gridView1.Columns[18].Visible = false;
                gridView1.Columns[10].Caption = "日期";
                gridView1.Columns[14].Caption = "收费单位名称";
                gridView1.Columns[16].Caption = "实际使用人";
            }

        }
        public void hidebutton()
        {
            this.btAdd.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.btEdit.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.btFind.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.btDelete.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            //this.btRefresh.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;

        }
        void gridViewOperation_BeforeAdd(object render, ObjectOperationEventArgs<VehicleActivity> e) {
         
        }
        void gridViewOperation_AfterAdd(object render)
        {

        }
        public void LoadData()
        {
            gridViewOperation.RefreshData(" where 1=1 and Act_Name='"+GetActName(operType)+"'order by StartDate desc,VehicleNumber");
        }
        public void LoadData2()
        {
            gridViewOperation.RefreshData(" where 1=1 and Act_Name='" + GetActName(operType) + "' and Date3<=getdate() and getdate()<=ExpirationDate  order by StartDate desc,VehicleNumber");
        }
        public string GetActName(string str)
        {
            if (str == "1")
            {
                return "保险";
            }
            if (str == "2")
            {
                return "年审";
            }
            if (str == "3")
            {
                return "养路";
            }
            if (str == "4")
            {
                return "二维";
            }
            if (str == "5")
            {
                return "洗车";
            }
            if (str == "6")
            {
                return "过路";
            }
            if (str == "7")
            {
                return "蓬靠";
            }
            else
            {
                return "NO";
            }
        }
        private void initImageList() {
            ImageList imagelist = new ImageList();
            imagelist.ImageStream = (Ebada.Client.Resource.UCGridToolbar.UCGridToolbarImageList);
            barManager1.Images = imagelist;
        }
        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) {
            if (FocusedRowChanged != null)
            {
                FocusedRowChanged(gridView1, gridView1.GetFocusedRow() as VehicleActivity);
               
            }
            row = gridView1.GetFocusedRow() as VehicleActivity;
        }
        /// <summary>
        /// 封装了数据操作的对象
        /// </summary>
        [Browsable(false)]
        public GridViewOperation<VehicleActivity> GridViewOperation {
            get { return gridViewOperation; }
            set { gridViewOperation = value; }
        }
        /// <summary>
        /// 新建对象设置Key值
        /// </summary>
        /// <param name="newobj"></param>
        void gridViewOperation_CreatingObjectEvent(VehicleActivity newobj) {
           
        }

    }
}
